#include "cobra11syndicate.hlsli"
#include "standard.hlsli"

struct PS_Input_C11Auto 
{
float4 v7 : SV_Position /* dcl vPos.xy */ ;
float3 normal : texcoord /* dcl_texcoord v2.xyz */ ;
float4 distanceToCamera : texcoord1 /* dcl_texcoord1 v3 */ ;
float4 v4 : texcoord2 /* dcl_texcoord2 v4.xy */ ;
float4 o6 : texcoord4 /* dcl_texcoord4 o6 */ ;
float4 o7 : texcoord6 /* dcl_texcoord6 o7 */ ;
float3 v5 : texcoord7 /* dcl_texcoord7 v5.xyz */ ;
float4 diffuseColor : texcoord8 /* dcl_texcoord8 v1 */ ;
float4 VertexColor : color /* dcl_color v0.w */ ;
};




float4 ps_main(PS_Input_C11Auto psInAuto) : SV_Target
{

float4 c0 = float4(8, -3.5, 0, 3); // def c0, 8, -3.5, 0, 3
float4 c1 = float4(0.308600008, 0.609399974, 0.0820000023, 1); // def c1, 0.308600008, 0.609399974, 0.0820000023, 1
float4 c2 = float4(1, 2, 3, 4); // def c2, 1, 2, 3, 4
float4 c3 = float4(1, 0, -1, -2); // def c3, 1, 0, -1, -2
float4 c4 = float4(20, 1.39999998, 0.800000012, 0.5); // def c4, 20, 1.39999998, 0.800000012, 0.5


float4 oC0 = (float4)0;
float4 r0 = (float4)0;
float4 r1 = (float4)0;
float4 r2 = (float4)0;
float4 r3 = (float4)0;
float4 r4 = (float4)0;
float4 r5 = (float4)0;



r0.x = dot(psInAuto.distanceToCamera.xyz, psInAuto.distanceToCamera.xyz);//dp3 r0.x, v3, v3
r0.x = rsqrt(r0.x);//rsq r0.x, r0.x
if (DitherFlag)
{ //if b4
r0.y = 1.0f / r0.x;//rcp r0.y, r0.x
r0.zw = psInAuto.v7.xy * DitherTexParams.xy +  DitherTexParams.zw;//mad r0.zw, vPos.xyxy, c20.xyxy, c20
r1.xyzw = TexDither.Sample(DitherTex, r0.zw);//texld r1, r0.zwzw, s15
r0.z = r1.w * DitherClipParams.y;//mul r0.z, r1.w, c21.y
r0.y = r0.y * DitherClipParams.x +  r0.z;//mad r0.y, r0.y, c21.x, r0.z
r1.xyzw = r0.y + DitherClipParams.z;//add r1, r0.y, c21.z
clip(r1.xyzw);//texkill r1
} //endif
r1.xyz = normalize(psInAuto.normal.xyz);//nrm r1.xyz, v2
r0.y = saturate(dot(r1.xyz, LightVec.xyz));//dp3_sat r0.y, r1, c14
if (ShadowsFlag)
{ //if b1
r0.z = psInAuto.v5.z * SelCascade.x +  SelCascade.y;//mad r0.z, v5.z, c35.x, c35.y
r0.z = log(r0.z);//log r0.z, r0.z
r0.z = r0.z * SelCascade.z +  SelCascade.w;//mad r0.z, r0.z, c35.z, c35.w
r1.w = max(r0.z, c0.z);//max r1.w, r0.z, c0.z
r0.z = min(r1.w, c0.w);//min r0.z, r1.w, c0.w
r0.w = frac(r0.z);//frc r0.w, r0.z
r0.w = r0.z + -r0.w;//add r0.w, r0.z, -r0.w
r2.xyzw = r0.z + c3.xyzw;//add r2, r0.z, c3
r3.xyzw = -r0.z + c2.xyzw;//add r3, -r0.z, c2
r4.xyzw = min(r2.xyzw, r3.xyzw);//min r4, r2, r3
r2.xyzw = max(r4.xyzw, c0.z);//max r2, r4, c0.z
r0.z = dot(r2.xyzw, ShadowNormalOffset.xyzw);// dp4 r0.z, r2, c22
r2.x = dot(r1.xyz, ShadowNormalMat._m00_m10_m20);//dp3 r2.x, r1, c17
r2.y = dot(r1.xyz, ShadowNormalMat._m01_m11_m21);//dp3 r2.y, r1, c18
r2.z = dot(r1.xyz, ShadowNormalMat._m02_m12_m22);//dp3 r2.z, r1, c19
r2.xyz = r2.xyz * r0.z +  psInAuto.v5.xyz;//mad r2.xyz, r2, r0.z, v5
r0.z = r0.w + -c2.y;//add r0.z, r0.w, -c2.y
r2.w = c1.w;//mov r2.w, c1.w
r3.xyzw = ShadowMats[0]._m02_m12_m22_m32;//mov r3, c38
r3.xyzw = float4(-abs(r0.w) < 0 ? r3.x : ShadowMats[1]._m02,
-abs(r0.w) < 0 ? r3.y : ShadowMats[1]._m12,
-abs(r0.w) < 0 ? r3.z : ShadowMats[1]._m22,
-abs(r0.w) < 0 ? r3.w : ShadowMats[1]._m32);
//cmp r3, -r0_abs.w, r3, c41
r4.xyzw = ShadowMats[2]._m02_m12_m22_m32;//mov r4, c44
r4.xyzw = float4(-r0.z < 0 ? r4.x : ShadowMats[3]._m02,
-r0.z < 0 ? r4.y : ShadowMats[3]._m12,
-r0.z < 0 ? r4.z : ShadowMats[3]._m22,
-r0.z < 0 ? r4.w : ShadowMats[3]._m32);
//cmp r4, -r0.z, r4, c47
r3.xyzw = float4(r0.z < 0 ? r4.x : r3.x,
r0.z < 0 ? r4.y : r3.y,
r0.z < 0 ? r4.z : r3.z,
r0.z < 0 ? r4.w : r3.w);
//cmp r3, r0.z, r4, r3
r3.z = dot(r2.xyzw, r3.xyzw);// dp4 r3.z, r2, r3
r4.xyzw = ShadowMats[0]._m00_m10_m20_m30;//mov r4, c36
r4.xyzw = float4(-abs(r0.w) < 0 ? r4.x : ShadowMats[1]._m00,
-abs(r0.w) < 0 ? r4.y : ShadowMats[1]._m10,
-abs(r0.w) < 0 ? r4.z : ShadowMats[1]._m20,
-abs(r0.w) < 0 ? r4.w : ShadowMats[1]._m30);
//cmp r4, -r0_abs.w, r4, c39
r5.xyzw = ShadowMats[2]._m00_m10_m20_m30;//mov r5, c42
r5.xyzw = float4(-r0.z < 0 ? r5.x : ShadowMats[3]._m00,
-r0.z < 0 ? r5.y : ShadowMats[3]._m10,
-r0.z < 0 ? r5.z : ShadowMats[3]._m20,
-r0.z < 0 ? r5.w : ShadowMats[3]._m30);
//cmp r5, -r0.z, r5, c45
r4.xyzw = float4(r0.z < 0 ? r5.x : r4.x,
r0.z < 0 ? r5.y : r4.y,
r0.z < 0 ? r5.z : r4.z,
r0.z < 0 ? r5.w : r4.w);
//cmp r4, r0.z, r5, r4
r3.x = dot(r2.xyzw, r4.xyzw);// dp4 r3.x, r2, r4
r4.xyzw = ShadowMats[0]._m01_m11_m21_m31;//mov r4, c37
r4.xyzw = float4(-abs(r0.w) < 0 ? r4.x : ShadowMats[1]._m01,
-abs(r0.w) < 0 ? r4.y : ShadowMats[1]._m11,
-abs(r0.w) < 0 ? r4.z : ShadowMats[1]._m21,
-abs(r0.w) < 0 ? r4.w : ShadowMats[1]._m31);
//cmp r4, -r0_abs.w, r4, c40
r5.xyzw = ShadowMats[2]._m01_m11_m21_m31;//mov r5, c43
r5.xyzw = float4(-r0.z < 0 ? r5.x : ShadowMats[3]._m01,
-r0.z < 0 ? r5.y : ShadowMats[3]._m11,
-r0.z < 0 ? r5.z : ShadowMats[3]._m21,
-r0.z < 0 ? r5.w : ShadowMats[3]._m31);
//cmp r5, -r0.z, r5, c46
r4.xyzw = float4(r0.z < 0 ? r5.x : r4.x,
r0.z < 0 ? r5.y : r4.y,
r0.z < 0 ? r5.z : r4.z,
r0.z < 0 ? r5.w : r4.w);
//cmp r4, r0.z, r5, r4
r3.y = dot(r2.xyzw, r4.xyzw);// dp4 r3.y, r2, r4
r3.w = c1.w;//mov r3.w, c1.w
r2.xyzw = TexShadowMap.Sample(ShadowMap, r3.xy / r3.w);//texldp r2, r3, s7
r2.w = r2.x;//mov r2.w, r2.x
}
else
{ //else
r0.z = saturate(psInAuto.VertexColor.w * c0.x +  c0.y);//mad_sat r0.z, v0.w, c0.x, c0.y
r2.w = -r0.z + c1.w;//add r2.w, -r0.z, c1.w
} //endif
r0.z = -r0.y + c1.w;//add r0.z, -r0.y, c1.w
r0.w = r0.z * r0.z;//mul r0.w, r0.z, r0.z
r0.z = r0.z * -r0.w +  c1.w;//mad r0.z, r0.z, -r0.w, c1.w
r0.y = r0.y * r0.z;//mul r0.y, r0.y, r0.z
r0.xzw = r0.x * psInAuto.distanceToCamera.xyz;//mul_pp r0.xzw, r0.x, v3.xyyz
r1.w = dot(r1.xyz, r0.xzw);//dp3_pp r1.w, r1, r0.xzww
r3.x = r1.w + r1.w;//add r3.x, r1.w, r1.w
r0.xzw = r3.x * r1.xyz +  -r0.xzw;//mad_pp r0.xzw, r3.x, r1.xyyz, -r0
r0.x = saturate(dot(r0.xzw, LightVec.xyz));//dp3_sat_pp r0.x, r0.xzww, c14
r0.z = saturate(-r1.w + c1.w);//add_sat_pp r0.z, -r1.w, c1.w
r0.zw = r0.zx * r0.zx;//mul r0.zw, r0.xyzx, r0.xyzx
r0.y = r0.x * r0.w +  r0.y;//mad_pp r0.y, r0.x, r0.w, r0.y
r0.z = r0.z * c4.z +  c4.w;//mad r0.z, r0.z, c4.z, c4.w
r0.y = r0.z * r0.y;//mul_pp r0.y, r0.z, r0.y
r1.x = pow(r0.x, c4.x);//pow r1.x, r0.x, c4.x
r0.x = r1.x * c4.y;//mul_pp r0.x, r1.x, c4.y
r2.xyz = r2.w * SunColor.xyz;//mul_pp r2.xyz, r2.w, c15
r1.xyzw = r2.xyzw * r0.x;//mul_pp r1, r2, r0.x
r3.xyzw = Tex1.Sample(DiffuseTex1, psInAuto.v4.xy);//texld r3, v4, s0
r1.xyzw = r1.xyzw * r3.w;//mul r1, r1, r3.w
r0.x = dot(r3.xyz, c1.xyz);//dp3 r0.x, r3, c1
r4.xyz = lerp(r3.xyz, r0.x, Exposure.w);//lrp r4.xyz, c23.w, r0.x, r3
r4.w = r3.w;//mov r4.w, r3.w
r0.xyzw = r0.y * r2.xyzw +  psInAuto.diffuseColor.xyzw;//mad_pp r0, r0.y, r2, v1
r0.xyzw = r4.xyzw * r0.xyzw +  r1.xyzw;//mad_pp r0, r4, r0, r1
r0.xyz = r0.xyz + -FogColor.xyz;//add r0.xyz, r0, -c29
oC0.xyz = psInAuto.distanceToCamera.w * r0.xyz +  FogColor.xyz;//mad_pp oC0.xyz, v3.w, r0, c29
oC0.w = r0.w;//mov_pp oC0.w, r0.w
return oC0;
}


